package com.brillilab.service.core.method.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.brillilab.dao.mapper.method.MethodTypeHideMapper;
import com.brillilab.domain.po.method.MethodTypeHide;
import com.brillilab.service.core.method.IMethodTypeHideService;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class MethodTypeHideServiceImpl implements IMethodTypeHideService {

    @Resource
    private MethodTypeHideMapper methodTypeHideMapper;

    @Override
    public List<MethodTypeHide> selectListByUserId(Long userId) {
        Assert.notNull(userId,"参数缺失！");
        return methodTypeHideMapper.selectList(
                new LambdaQueryWrapper<MethodTypeHide>()
                        .eq(MethodTypeHide::getUserId,userId));
    }

    @Override
    public boolean insertBatch(List<MethodTypeHide> adds) {
        return methodTypeHideMapper.insertBatch(adds) >= 0;
    }

    @Override
    public boolean deleteBatch(List<Long> deletes) {
        return methodTypeHideMapper.deleteBatchIds(deletes) >=0;
    }

    @Override
    public boolean deleteByMethodTypeIds(List<Long> methodTypeIds,Long userId) {
        return methodTypeHideMapper.delete(
                new LambdaQueryWrapper<MethodTypeHide>()
                        .eq(MethodTypeHide::getUserId,userId)
                        .in(MethodTypeHide::getMethodTypeId,methodTypeIds)) >=0;
    }

    @Override
    public List<MethodTypeHide> selectListByMethodTypeIds(List<Long> methodTypeIds,Long userId) {
        return methodTypeHideMapper.selectList( new LambdaQueryWrapper<MethodTypeHide>()
                .eq(MethodTypeHide::getUserId,userId)
                .in(MethodTypeHide::getMethodTypeId,methodTypeIds));
    }

    @Override
    public int selectCount(Long userId) {
        return methodTypeHideMapper.selectCount(
                new LambdaQueryWrapper<MethodTypeHide>()
                        .eq(MethodTypeHide::getUserId,userId));
    }

    @Override
	public MethodTypeHide selectMethodTypeHide(Long userId, Long methodTypeId) {
		List<MethodTypeHide> list = methodTypeHideMapper.selectList(
                new LambdaQueryWrapper<MethodTypeHide>()
                        .eq(MethodTypeHide::getUserId, userId)
                        .eq(MethodTypeHide::getMethodTypeId, methodTypeId));
		return CollectionUtils.isNotEmpty(list)?list.get(0):null;
	}
}
